/**
 * 
 */
package cn.springsoter.core.launch.config;

import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import com.google.common.collect.Lists;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.servers.Server;

 
/**
 * @author kevin
 *
 */
@PropertySource("classpath:swagger.properties")
@Configuration
public class OpenApiConfig {
	
	@Value("${spring.application.name}")
	private String applicationName;
	
	@Value("${server.port}")
	private Integer port;
	
    @Bean
    public OpenAPI springShopOpenAPI() {
        Components components = new Components();
        
        // 添加auth认证header
//        components.addSecuritySchemes(HttpHeaders.AUTHORIZATION, 
//        		new SecurityScheme()
//        		.type(SecurityScheme.Type.HTTP)
//        		.bearerFormat("JWT")
//        		.in(In.HEADER)
//        		.scheme("bearer"));
        
        // 添加全局header
//        components.addParameters("myHeader1", new Parameter().in(In.HEADER.toString()).schema(new StringSchema()).name("myHeader1"));
//        components.addHeaders("myHeader2", new Header().description("myHeader2 header").schema(new StringSchema()));
        
        Server serverLocal = new Server();
        serverLocal.setUrl("http://localhost:" + port);
        serverLocal.setDescription("本地地址");
//        Server serverDev1 = new Server();
//        serverDev1.setUrl("https://dev.healthlink.com");
//        serverDev1.setDescription("dev环境地址");
//        Server serverTest1 = new Server();
//        serverTest1.setUrl("https://test.healthlink.com");
//        serverTest1.setDescription("test1环境地址");
//        Server serverProd = new Server();
//        serverProd.setUrl("https://api.healthlink.com");
//        serverProd.setDescription("生产环境地址");
        
        List<Server> servers = Lists.newArrayList(serverLocal);
        
        return new OpenAPI()
                .components(components)
                .servers(servers)
                .info(new Info().title(applicationName + "接口文档")
                .description("OpenApi3.0")
                .version("1.0.0")
                .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0.html")))
                .externalDocs(new ExternalDocumentation()
                .description("SpringDoc OpenAPI Documentation")
                .url("https://springdoc.org/"));
    }
}
